from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QLineEdit, QPushButton

from PyQt5.QtGui import QIntValidator
import var


class SettingParams:
    def __init__(self, successListener):
        self.successListener = successListener


def CreateSettingWindow(screen, new_Params, ui_main):
    win = QDialog()
    win.setWindowFlags(Qt.WindowCloseButtonHint)
    win.setWindowTitle('设置')
    width = 400
    height = 300
    win.setGeometry((screen.width - width) / 2, (screen.height - height) / 2, width, height)

    outline_vg = QVBoxLayout()

    text_subline = QLabel("--------------------")
    outline_vg.addWidget(text_subline)

    outline_vg.addWidget(QLabel("时间间隔: "))

    time_split = QLineEdit(f"{var.time_split}")
    time_split.setValidator(QIntValidator())
    outline_vg.addWidget(time_split)

    outline_vg.addWidget(QLabel("随机生成数量: "))

    rand_num = QLineEdit(f"{var.rand_num}")
    rand_num.setValidator(QIntValidator())
    outline_vg.addWidget(rand_num)

    ok_button = QPushButton("确定")
    ok_button.clicked.connect(
        lambda: new_Params.successListener(win, time_split.text(), rand_num.text(), ui_main))
    outline_vg.addWidget(ok_button)

    outline_vg.addStretch()
    win.setLayout(outline_vg)
    return win
